/*    */ package com.zimbra.cs.servlet.continuation;
/*    */ 
/*    */ import com.zimbra.common.util.Log;
/*    */ import com.zimbra.common.util.ZimbraLog;
/*    */ import java.util.concurrent.atomic.AtomicBoolean;
/*    */ import javax.servlet.ServletRequest;
/*    */ import org.eclipse.jetty.continuation.Continuation;
/*    */ import org.eclipse.jetty.continuation.ContinuationListener;
/*    */ import org.eclipse.jetty.continuation.ContinuationSupport;
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ public class ResumeContinuationListener
/*    */   implements ContinuationListener
/*    */ {
/*    */   private Continuation continuation;
/*    */   private AtomicBoolean readyToResume;
/*    */   
/*    */   public ResumeContinuationListener(Continuation continuation)
/*    */   {
/* 40 */     this.continuation = continuation;
/* 41 */     this.readyToResume = new AtomicBoolean(false);
/* 42 */     continuation.addContinuationListener(this);
/*    */   }
/*    */   
/*    */   public static ResumeContinuationListener getResumableContinuation(ServletRequest request) {
/* 46 */     return new ResumeContinuationListener(ContinuationSupport.getContinuation(request));
/*    */   }
/*    */   
/*    */   public void onComplete(Continuation continuation)
/*    */   {
/* 51 */     this.readyToResume.set(false);
/*    */   }
/*    */   
/*    */   public void onTimeout(Continuation continuation)
/*    */   {
/* 56 */     this.readyToResume.set(false);
/*    */   }
/*    */   
/*    */ 
/*    */ 
/*    */   public synchronized void resumeIfSuspended()
/*    */   {
/* 63 */     if (this.readyToResume.compareAndSet(true, false)) {
/*    */       try {
/* 65 */         this.continuation.resume();
/*    */       } catch (IllegalStateException ise) {
/* 67 */         if ((!this.continuation.isExpired()) && (!this.continuation.isResumed()))
/*    */         {
/*    */ 
/* 70 */           throw ise;
/*    */         }
/* 72 */         ZimbraLog.misc.debug("ignoring IllegalStateException during resume; already resumed/expired", ise);
/*    */       }
/*    */     }
/*    */   }
/*    */   
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */   public synchronized void suspendAndUndispatch(long timeout)
/*    */   {
/* 83 */     this.readyToResume.set(true);
/* 84 */     this.continuation.setTimeout(timeout);
/* 85 */     this.continuation.suspend();
/* 86 */     this.continuation.undispatch();
/*    */   }
/*    */   
/*    */   public Continuation getContinuation() {
/* 90 */     return this.continuation;
/*    */   }
/*    */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/servlet/continuation/ResumeContinuationListener.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */